/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

/**
 *
 * @author trinhnta
 */
public class DBUtils {
    private static String username;
    private static String password;
    private static String driver;
    private static String url;
    private static Connection con;

    public static Connection makeConnection(){
        try {
            getResource();
            Class.forName(driver);
            con = DriverManager.getConnection(url,username,password);
            return con;
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());;
        } catch (ClassNotFoundException ex) {
            System.out.println(ex.getMessage());;
        }
        return null;
    }

    public static void getResource(){
        ResourceBundle rb = ResourceBundle.getBundle("DB");
        driver = rb.getString("driver");
        url = rb.getString("url");
        password = rb.getString("password");
        username = rb.getString("username");
    }
}
